from flask import session,current_app,g,jsonify
from info.utils.response_code import RET


# 点击排行中根据排序返回不同类名
# 自定义过滤器
def do_index_class(index):
    """自定义过滤器，过滤点击排序html的class"""
    if index == 0:
        return "first"
    elif index == 1:
        return "second"
    elif index == 2:
        return "third"
    else:
        return ""

# 用户登陆信息装饰器
import functools
def user_login_data(f):
    @functools.wraps(f)
    def wapper(*args,**kwargs):
        user_id=session.get('user_id')
        user=None
        if user_id:
            try:
                from info.models import User
                user=User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user=user
        return f(*args,**kwargs)
    return wapper